package com.hualan.servlet;

import com.alibaba.fastjson.JSON;
import com.hualan.dao.CommunityDeleteDao;
import com.hualan.dao.impl.CommunityDeleteDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;


@WebServlet("/community/communityDelete")
public class CommunityDeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map<String,Object> map = new HashMap<>();
        String communityId = req.getParameter("communityId");
        int cid = Integer.parseInt(communityId);
        CommunityDeleteDao communityDeleteDao = new CommunityDeleteDaoImpl();
        int row = communityDeleteDao.deleteCommunity(cid);
        if (row < 0){
            map.put("code",302);
            map.put("message","更新失败");
        }else{
            map.put("code",200);
            map.put("message","更新成功");
        }
        resp.getWriter().write(JSON.toJSONString(map));
    }
}
